/*
 * @Author: sjr
 * @Date: 2021-01-31 11:34:44
 * @LastEditTime: 2021-01-31 15:56:32
 * @LastEditors: sjr
 * @Description: 描述
 * @FilePath: \leetcode\102.二叉树的层序遍历.js
 */
/*
 * @lc app=leetcode.cn id=102 lang=javascript
 *
 * [102] 二叉树的层序遍历
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[][]}
 */
var levelOrder = function(root) {
  let res = []
  const levelOrder = (node, level) => {
    if(!node) return
    res[level] = res[level] || [] // 初始换层级数据
    res[level].push(node.val)

    levelOrder(node.left, level + 1)
    levelOrder(node.right, level + 1)
  }
  levelOrder(root, 0)
  return res
};
// @lc code=end

